<?php

namespace app\admin\model\yiliao;

use think\Model;


class Pro extends Model
{

    

    

    // 表名
    protected $name = 'yiliao_pro';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'isdata_text',
        'status_text',
        'createtime_text',
    ];
    

    
    public function getIsdataList()
    {
        return ['yes' => __('Yes'), 'no' => __('No')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getIsdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['isdata']) ? $data['isdata'] : '');
        $list = $this->getIsdataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

	public function cate(){
		return $this->belongsTo('Procate', 'yiliao_procate_id', 'id', [], 'LEFT')->setEagerlyType(0);
	}
    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


}
